package net.hn.hnms.biz.energy.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.energy.service.PowerAnalysisService;
import net.hn.hnms.biz.energy.vo.PowerStatisticsInfoVo;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "用电统计", tags = {"用电统计"})
@RestController
@RequestMapping("/power/statistics")
@EnableScheduling
public class PowerAnalysisController extends BaseController {

    @Autowired
    private PowerAnalysisService powerAnalysisService;


    @ApiOperation("定时计算用电数据并插入，每天凌晨3点运行")
    @Scheduled(cron = "30 10 03 * * ? ")
    @GetMapping("/getPowerConsumptionAnalysisScheduled")
    public R<Void> add() {
        System.out.println("-----------------------------------执行定时--------------------------");
        powerAnalysisService.calculationPower();
        return R.ok();
    }

    /**
     * 2022/12/20
     * @param year 年
     * @param mineCode
     * @return
     */
    @ApiOperation("获取用电分析统计汇总")
    @GetMapping("/getPowerConsumptionAnalysisByYear/{year}")
    @AutoSetMineCode
    public R<List<PowerStatisticsInfoVo>> getPowerConsumptionAnalysisByYear(@PathVariable String year, String mineCode) {
        return R.ok(powerAnalysisService.selectPowerConsumptionAnalysisByYear(year,mineCode));
    }


    /**
     * 2022/12/20
     * @param beginDate
     * @param mineCode
     * @return
     */
    @ApiOperation("获取用电分析统计详情根据年月")
    @GetMapping("/getPowerConsumptionAnalysisDetails/{beginDate}/{flag}")
    @AutoSetMineCode
    public R<ResponsePage<PowerStatisticsInfoVo>> getPowerConsumptionAnalysisDetails(PageQuery pageQuery, @PathVariable String beginDate, @PathVariable Integer flag, String mineCode) {
        return R.ok(powerAnalysisService.selectPowerConsumptionAnalysisDetails(pageQuery,beginDate,flag,mineCode));
    }

}
